<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
	</body>
	<script>
		const add = (...numbers) => numbers.reduce((x,y) => x+y);
		let numbers = [1,2,3,4,5,6,7,8,9,10]
		console.log(add(...numbers));
		const push = (arr,...items) => arr.concat([...items]);
		const push1 = (arr,...items) => [...arr,...items];
		console.log(push([1,2,3],4,5,6,7,8,9));
		console.log(push1([1,2,3],4,5,6,7,8,9));
		let arr1 = [0, 1, 2];
		let arr2 = [3, 4, 5];
		var newArr = [1,2,3,4].push(...[4,5,6]);
		console.log(newArr);
		console.log(arr1.push(...arr2)+"将一个数组添加到另一个数组的尾部");
		const a1 = ['a','b','c'];
		const a2 = [...a1];//深度复制，不会污染a1
		const [...a3] = a1;//深度复制，不会污染a1
		console.log(a2);
		console.log(a3);
		a2[0] = 'haha';
		console.log(a2);
		console.log(a1);
		console.log([...[1,2,3],...[4,5,6]]);
		console.log([...'helloworld']);
		console.log([...[1,2,3],...'456'].map((x) => Number(x)));
		//如果将扩展运算符用于数组赋值，只能放在参数的最后一个，否则报错
		let map1 = new Map([
			['first','one'],
			['second','two'],
			['third','three']
		]);
		console.log([...map1.keys()]);
		console.log([...map1.values()]);
		const go = function*(){
			yield 1;
			yield 2;
			yield 3;
		}
		console.log([...go()]);
		Object.prototype.length = function(){
			let count = 0;
			for(let i in this){
				count ++;
			}
			return count;
		}
		let arrayLike = {
			'0':'a',
			'1':'b',
			'2':'c',
			'3':'d'
		};
		arrayLike.length = arrayLike.length()-1;
		console.log(Array.from(arrayLike));
		const cs = '123456';
		console.log(Array.from(cs).map((x) => Number(x)));
		function foo(...cs){
			console.log(Array.from(arguments).map((x) => Number(x)));
		}
		foo(...cs);
		console.log(Array.of(3));
		console.log(new Array(10).fill(0));
	</script>
</html>
